﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RaisingStudio.SmallProgram.Library.Internal
{
    public static class Midi
    {
        private static int _midiOut = 0;

        public static void ChangeInstrument(int number)
        {
            uint dwMsg = BitConverter.ToUInt32(new byte[] { 0xc0, (byte)number, 0, 0 }, 0);
            NativeHelper.midiOutShortMsg(_midiOut, dwMsg);
        }

        public static void EnsureDeviceInit()
        {
            if (_midiOut == 0)
            {
                NativeHelper.midiOutOpen(ref _midiOut, 0, 0, 0, 0);
                ChangeInstrument(0);
            }
        }

        public static void PlayNote(int number)
        {
            uint dwMsg = BitConverter.ToUInt32(new byte[] { 0x90, (byte)number, 100, 0 }, 0);
            NativeHelper.midiOutShortMsg(_midiOut, dwMsg);
        }
    }
}
